package com.example.rental.service.impl;

import com.example.rental.entity.Admin;
import com.example.rental.entity.dto.AdminDto;
import com.example.rental.mapper.AdminMapper;
import com.example.rental.result.Result;
import com.example.rental.service.AdminService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Data

public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Admin adminLogin(String phone, String password) {

        return adminMapper.selectByPhoneAndPwd(phone, password);
    }

    @Override
    public Integer addAdmin(String rphone, String rpassword) {
        return adminMapper.addAmin(rphone,rpassword);
    }

    @Override
    public Admin findByPhone(String phone) {
        return adminMapper.findByPhone(phone);
    }
    @Override
    public Result searchAdmin(AdminDto adminDto) {
        PageHelper.startPage(adminDto.getPage(), adminDto.getLimit());
        List<Admin> list = adminMapper.searchAdmin(adminDto);
        Page page = (Page) list;
        Result<Page> result = Result.ok(page);
        result.setCount(page.getTotal());

        return result;
    }
    @Override
    public void updateAdmin(Admin admin){adminMapper.updateAdmin(admin);};
}